<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored ="false"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String dataValueBeanStr = (String)request.getAttribute("dataValueBeanStr");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>北京市电子行政监察平台-通信录</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="<%=path%>/css/base.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/style.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/frame.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/jquery-tree-1.1.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/directories.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/directories.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript">
			var path = "<%=path%>";
		</script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery-1.4.3.pack.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery.timers-1.2.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery-ui-1.8.6.custom.min.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery-jtemplates.pack.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery.treeview.pack.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery.metadata.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/core/jquery.validate.fixed.pack.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/config/config.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/system/util.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/system/oacore.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/system/accountBook.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/system/jquery-tree-1.1.js"></script>
		<script type="text/javascript" src="<%=path%>/javascript/system/init.js"></script>
		<script language="javascript" type="text/javascript" src="<%=path%>/javascript/My97DatePicker/WdatePicker.js"></script>
		<style type="text/css">
			div {
				position: static;
			}
			.display_Floater{                     /*浮动窗口*/
				background-color: #FAFEFF;
				width:298px;
				height:148px;
				border:1px solid #7d8791;
			}
			.floater_top{
				width:100%;
				height:37px;
				font-size:14px;
				background:url(../image/contacts/top_bg.gif) repeat-x;
			}
			.top_group{
				margin:5px 10px;
				width:30px;
				height:26px;
				float:left;
			}
			.top_text{
				line-height:37px;
			}
			.middle_align{
				line-height:60px;
				_line-height:30px;
				font-size:12px;
				margin:0 40px;
				_margin:20px 40px;
				text-align: center;
			}
			.btn_public{
				font-size:14px;
				height:28px;
				width:78px;
				line-height:28px;
				cursor:pointer;
			}
			.btn_confirm{
				background:url(../image/contacts/btn_confirm.gif) repeat-x;
				border: none;
				outline:none;
				float:left;
				margin-left:60px;
				margin-right:15px;
				position:relative;
			}
			.top_wrong{
				margin:8px;
				width:22px;
				height:21px;
				float:left;
			}
			.btn_cancel{
				background:url(../image/contacts/btn_cancel.gif) repeat-x;
				outline:none;
				border: none;
				float:left;
				position:relative;
			}
			.checked_li{
				background-color:#326ABF;
				color:white;
			}
			#orgTreeDiv{
				display:none;
				z-index:10;
				position:absolute;
				width:300px;
				height:400px;
				overflow-y:auto;
				overflow-x:hidden;
				background-color:#fff;
				border:1px #8FA4F5 solid; 
				padding:1px;
			}
		</style>
		<script type="text/javascript">
			var groupType = null;
			var tree;
			var tree2;
			$(function () {
				$(document.body).click(function(event){
					$("#letter").hide();
					var parentId = $(event.target).parents("#orgTreeDiv").attr("id");
					if(event.target.id!='contactUnitName'&&parentId!='orgTreeDiv'){
						$("#orgTreeDiv").hide();
						$("#group").hide();
						if($(".ui-dialog").css("display")!='block'){
							$("select[id!=contacttype][id!=sex][id!=positionId]").show();
						}
					};
				}).bind("keydown", function (event) {
					if(event.keyCode == 27)//Ese键
						$("select").show();
					if(event.keyCode == 13){
						$("#contact").stopTime('query');
						queryUser();
					}
				});
				//生成树
				var orgId="";
				var treeData = "<%=request.getAttribute("organizationDTOs")%>";
				var BE_UPDATESOURCE_NODE = {};
				function pushBeUpdateNodeData(list) {
					if(list){
						var size = list.length;
						for(var i=0;i<size;++i){
							var org = list[i];
							BE_UPDATESOURCE_NODE[org.orgId] = org;
						}
					}
				};
				function popBeUpdateNodeData(id) {
					var data = BE_UPDATESOURCE_NODE[id];
					delete BE_UPDATESOURCE_NODE[id];
					return data;
				};
				function getNodeById(id) {
					var found;
					$("span.jqtree-node-content").each(function () {
						if(id == parseInt($(this).attr("id"))){
							found = this;
							return false;
						}
					});
					return found;
				};
				function updateAllSource() {
					for(var id in BE_UPDATESOURCE_NODE) {
						var beUpdateNode = getNodeById(id);
						if(beUpdateNode)
							$(beUpdateNode).data("source", popBeUpdateNodeData(id));
					}
				};
				tree = new $.Tree({
					parent: $("#treeArea"),
					source: $.parseJSON(treeData),
					selectMode: "single",
					sourceQuote: true,
					pretreatment: function (node) {
						var pedNode = {};
						pedNode.id = node.id += "_" + node.version + "_" + node.content;
						pedNode.content = "<span name='"+node.content+"' class='node-value'>" + node.content + "</span>";
						if(node.child && node.child.length > 0)
							pedNode.children= node.child;
						return pedNode;
					},
					onSelect: function (node) {openDetail(node.id);}
				});
				function openDetail(nodeId) {
					var idInfo = nodeId.split("_");
					var params = {};
					orgId=params;
					params[ACTIONS.ORG_DETAIL.params.ORG_ID] = idInfo[0];
					params[ACTIONS.ORG_DETAIL.params.VERSION] = idInfo[1];
					$.util.Data.request({
						url: "findContactByOrgId.action",
						data: params,
						async: false,
						dataType: 'text',
						type: "post",
						success: function (data) {$("#contact").html(data);initBetween();},
						error: function () {$("#contact").html("获取详细信息失败!");}
					});
				};
				tree2 = new $.Tree({
					parent: $("#orgTreeDiv"),
					source: $.parseJSON(treeData),
					selectMode: "single",
					sourceQuote: true,
					pretreatment: function (node) {
						var pedNode = {};
						pedNode.id = node.id += "_" + node.version + "_" + node.content;
						pedNode.content = "<span name='"+node.content+"' class='node-value'>" + node.content + "</span>";
						if(node.child && node.child.length > 0)
							pedNode.children= node.child;
						return pedNode;
					},
					onSelect: function (node) {selectOrg(node.id);}
				});
				function selectOrg(nodeId){
					var idInfo = nodeId.split("_");
					var params = {};
					orgId=params;
					params[ACTIONS.ORG_DETAIL.params.ORG_ID] = idInfo[0];
					params[ACTIONS.ORG_DETAIL.params.VERSION] = idInfo[1];
					$('#contactUnitName').val(idInfo[2]);
					$("select").show();
					$("#orgTreeDiv").css("display","none");
					$.util.Data.request({
						url: "findPositionByOrgId.action",
						data: params,
						async: false,
						dataType: 'json',
						type: "post",
						success: function(data) {
							var objSelect = $("#positionId").get(0);
							objSelect.options.length = 0;
							if(data.length==0){
								objSelect.options.add(new Option("请选择",""));
							}else{
								objSelect.options.add(new Option("请选择",""));
								for(var i=0;i<data.length;i++){
									objSelect.options.add(new Option(data[i].positionName,data[i].positionId));
								}
							}
						}
					});
				}
				//生成树结束 
				//随树宽度变化改变
				$("#treeArea").resize(function(){
					changeWidth();
				});
				<sec:authorize  ifAllGranted="通讯录操作" >
					$(".btn_person_change").show();
				</sec:authorize>
				//初始化获取公共组
				initContact();
				//获取某个组 组表单的动态样式
				$("div.tab_general").click(function(event){
					$("#contact").html("");
					var group = event.target;
					groupType = $(group).attr("id");
					initContact();
					$("div.tab_general[class$=tab_blue]").attr("checked","").removeClass("tab_blue").addClass("tab_gray");
					$(group).removeClass("tab_gray").addClass("tab_blue").attr("checked","checked");
					if(groupType=="org"){
						$("#modifyGroup").hide();
						$("#showTree").show();
					}else if(groupType=="public"){
					    $("#modifyGroup").hide();
						$("#showTree").hide();
						<sec:authorize  ifAllGranted="通讯录操作" >
							$("#modifyGroup").show();
						</sec:authorize>
					}else{
						$("#showTree").hide();
						$("#modifyGroup").show();
					}
				});
				//全选,反选
				$("#checkedAll").click(function(){
					$("input[name=checkbox]").each(function(){$(this).attr("checked",true)});
				});
				$("#unCheckedAll").click(function(){
					$("input[name=checkbox]").each(function(){
						if($(this).attr("checked")){
							$(this).attr("checked",false);
						}
						else{
							$(this).attr("checked",true);
						}
					});
				});
				//查询文本框
				$("#search_text").focus(function(){
					var searchStr = $("#search_text").val();
					if(searchStr=='输入联系人'){
						$(this).val("");
					}
				}).blur(function(){
					var searchStr = $("#search_text").val();
					if(searchStr==''){
						$(this).val("输入联系人");
					}
				});
				//查询按钮
				$("#search_btn").click(function(){
					$("#contact").stopTime('query');
					queryUser();
				});
				//字母图标
				$("#search_img").toggle(
					function(){
						var offset = $(this).offset();
						var height = $(this).height();
						$("#letter").show().css("z-index","1000")
						.css("left",offset.left)
						.css("top",offset.top+height);
					},
					function(){
						if($("#letter").css("display")=='none'){
							$("#letter").show();
						}else{$("#letter").hide();}
					}
				);
				//选择一组条件
				$("div#letter >ul").click(function(event){
					$("#contact").stopTime('query');
					var li = event.target;
					var searchStr = $(li).attr("id");
					var temp = $("div.group_outline > div.group_list[checked=checked]").attr("id");
					var searchType = (temp==null?"allContact":temp);
					$(li).addClass("checked_li");
					$.util.Data.request({
						url:"getContactListByCondition.action",
						data:{'queryType':'02','searchType':searchType,'contactQuery':searchStr},
						type:'post',
						dataType:'text',
						success:function(data){
							$(li).removeClass("checked_li");
							$("#letter").hide();
							$("#contact").html(data);
							var nothing = $("#nothing").html();
							if(nothing!=null){
								initContact();
								$("#contact").oneTime(2000,'query',function(){
									$("#allContact").addClass("group_list_sel");
									getUsers("allContact");
									$("#moveUser").hide();
									$("#delUser").hide();
								});
							}else{initBetween();}
						},
						error:function(){
							$(li).removeClass("checked_li");
							$("#letter").hide();
						}
					});
				});
				//人员组件操作
				$(".btn_person_change").click(function(){
					var ul = $(this);
					var operate = $(ul).attr("id");
					if($("input[type=checkbox]:checked").length==0){
						$("#group").hide();
						alert("请选择联系人");
						return;
					};
					if(operate!="delUser"){
						//获取组可操作组列表
						$.util.Data.request({
							url:"getAllContactGroupByCurrentUserId.action",
							type:'post',
							dataType:'json', 
							success:function(data){
								var str = "";
								if((data['1239']==null||data['1239']=="")&&(data['1240']==null||data['1240']=="")){
									str="还未建立个人组";
									<sec:authorize  ifAllGranted="通讯录操作" >
									str="还未建立联系人组";
									</sec:authorize>
									alert(str);
									return;
								}
								if(data['1239']!=null&&data['1239']!=""){
									for(var i=0;i<data['1239'].length;i++){
										str += "<li id='"+data[1239][i].groupId+"'>"+data[1239][i].groupName+"</li>"
									}
								}
								if(data['1239']!=null&&data['1239']!=""&&data['1240']!=""){
									str+="------------"
								}
								if(data['1240']!=null&&data['1240']!=""){
									for(var i=0;i<data[1240].length;i++){
										str += "<li id='"+data[1240][i].groupId+"'>"+data[1240][i].groupName+"</li>"
									}
								}
								$("#groupUl").html(str);
								operateUser(ul);
								betweenOper(operate);
							}
						});
					}else{
						$("#group").hide();
						$("#delMsg").oneTime(200,function(){opendialog("delMsg")});
						$("div#dels > button.btn_confirm").attr("id","GroupUserDel");
						$("#delTitle").html("删除联系人");
						$("#delConfirm").html("确定要移除该联系人?");	
					}
				});
				//树操作
				$("#openAll").toggle(
					function () {
						$(this).html("全部关闭");
						tree.openAll();
						$(".edit_area").css("width",$("#treeArea").width());
					},
					function () {
						$(this).html("全部展开");
						tree.closeAll();
						$(".edit_area").css("width","240px");
					}
				);
				//组编辑
				$("#editGroupName").dialog( {
					bgiframe : true,
					autoOpen : false,
					height : 194,
					width : 298,
					modal : true,
					resizable : false
				});
				//删除层
				$("#delMsg").dialog( {
					bgiframe : true,
					autoOpen : false,
					height : 194,
					width : 298,
					modal : true,
					resizable : false
				});
				//成功提示
				$("#success").dialog( {
					bgiframe : true,
					autoOpen : false,
					height : 70,
					width : 480,
					modal : true,
					resizable : false
				});
				//失败提示
				$("#failure").dialog( {
					bgiframe : true,
					autoOpen : false,
					height : 70,
					width : 480,
					modal : true,
					resizable : false
				});
				//添加组
				$("#addGroup").click(function(){
					if(groupType == "private"){
						$("#saveOrUpdate").html("新增个人组");
					}else{
						$("#saveOrUpdate").html("新增公共组");
					}
					opendialog("editGroupName");
					$("input[name=groupName]").val("");
					$("#edit_group").hide();
					$("#save_group").show();
				});
				//编辑组
				$("#editGroup").click(function(){
					var name = $("div.group_outline > div.group_list[checked=checked]").attr("name");
					if(name==null||name==""){
						alert("请先选择要修改的组");
						return;
					}
					$("input[name=groupName]").val(name);
					if(groupType == "private"){
						$("#saveOrUpdate").html("编辑个人组");
					}else{
						$("#saveOrUpdate").html("编辑公共组");
					}
					opendialog("editGroupName");
					$("#save_group").hide();
					$("#edit_group").show();
				});
				//删除组
				$("#delGroup").click(function(){
					var id = $("div.group_outline > div.group_list[checked=checked]").attr("id");
					if((id==null||id=="")||(id=='inContact'||id=='allContact')){
						alert("请先选择要删除的组");
						return;
					}else{
						$("#delMsg").oneTime(200,function(){opendialog("delMsg")});
						$("div#dels > button.btn_confirm").attr("id","GroupDel");
						$("#delTitle").html("删除组");
						$("#delConfirm").html("确定要删除该组?");						
					};
				});
				$("div#dels > button.btn_confirm").click(function(){
					var delId = $(this).attr("id");
					var sourceGroupId = $("div.group_outline > div.group_list[checked=checked]").attr("id");
					if(delId=='GroupDel'){//删除组
						$.util.Data.request({
							url:"delContactGroup.action",
							data:{"groupId":sourceGroupId},
							type:'post',
							success:function(data){
								if(data == false){
									openMsg("failure");
									$("#errMsg1").html("该组包含人员，不允许删除");
								}else{
									openMsg("success");
									$("#succMsg").html("删除组成功");
									initContact();
								}
							},
							error:function(){
								openMsg("failure");
								$("#errMsg1").html("删除组出错");
							}
						});
					}
					if(delId=='GroupUserDel'){//删除组内联系人
						var groupId = sourceGroupId;
						var ids = "";
						$("input[type=checkbox]:checked").each(function(i){
							ids+=$(this).val()+",";
						});
						ids=ids.substring(0,ids.length-1);
						$.util.Data.request({
							url:"removeContactFromGroup.action",
							data:{'contactIds':ids,'sourceGroupId':sourceGroupId},
							type:'post',
							dataType:'text',
							success:function(data){
								$("#group").hide();
								initContact();
								$("#contact").oneTime(200,function(){
									$("#"+groupId).addClass("group_list_sel").attr("checked","checked");
									getUsers(groupId);
								});
							}
						});
					}
					if(delId=='UserDel'){//删除联系人
						$.util.Data.request( {
							url : "delContact.action",
							type : 'post',
							data:{'contactId':$("#conId").val()},
							dataType : 'text',
							success : function(data) {
								document.getElementById('showContactInfo').style.display = "none";
								document.getElementById('editContact').style.display = "none";
								openMsg("success");
								$("#succMsg").html("删除联系人成功");
								initContact();
								getUsers("allContact");
							}
						});
					}
					closedialog("delMsg");
				});
				$("#cancelBtn").click(function(){
					closedialog("delMsg");
				});
				//编辑组按钮
				$("#edit_group").click(function(){
					var id = $("div.group_outline > div.group_list[checked=checked]").attr("id");
					groupType = $(".tab_general[checked=checked]").attr("id");
					var editUrl = null;
					var type = (groupType=="private")?1240:1239;
					if($("#groupName").val() == null || $("#groupName").val() == ""){

					}else{
						$.util.Data.request({
							url:"updateContactGroup.action",
							type:'post',
							data:{'groupId':id,'groupType':type,'groupName':$("#groupName").val()},
							dataType:'text', 
							success:function(data){
								if(data){
									openMsg("failure");
									$("#errMsg1").html("组名称重复");
								}else{
									openMsg("success");
									$("#succMsg").html("修改组名称成功");
									initContact();
								}
							},
							error:function(){
								openMsg("failure");
								$("#errMsg1").html("修改组名称出错");
							}
						});
						closedialog('editGroupName');
					}
				});
				//保存组按钮
				$("#save_group").click(function(){
					groupType = $(".tab_general[checked=checked]").attr("id");
					var saveUrl = null;
					if($("#groupName").val() == null || $("#groupName").val() == ""){

					}else{
						var type = (groupType=="private")?1240:1239;
						$.util.Data.request({
							url:"savaContactGroup.action",
							type:'post',
							data:{'groupType':type,'groupName':$("#groupName").val()},
							dataType:'test', 
							success:function(data){
								if(data){
									openMsg("failure");
									$("#errMsg1").html("组名称重复");
									initContact();
								}else{
									openMsg("success");
									$("#succMsg").html(groupType == "private"?"添加个人组成功":"添加公共组成功");
									initContact();
								}
							},
							error:function(){
								openMsg("failure");
								$("#errMsg1").html(groupType == "private"?"添加个人组出错":"添加公共组出错");
								$("#errMsg2").html("");
								initContact();
							}
						});
						closedialog('editGroupName');
					}
				});
				//关闭编辑组层
				$("#close_group").click(function(){
					closedialog('editGroupName');
				});
				//添加联系人
				$("#addContact").click(function(){
					$.util.Data.request({
						url:"addContactInput.action",
						type:'post',
						dataType:'test', 
						success:function(data){
							$.validator.addMethod("contactCode", function (value, element) {
								if(!value||value.length <= 0)
									return true;
								return /^[1-9][0-9]{5}$/.test(value);
							}, '邮政编码应该为6位数字');
							$.validator.addMethod("contactName", function (value, element) {
								if(!value||value.length <= 0)
									return false;
								return value != "姓名";
							}, '请填写联系人姓名！');
							$("#detailContact").html(data);
							$('#contactUnitName').focus(function(){
								tree2.openAll();
								var A_top = $(this).offset().top + $(this).outerHeight(true);
								var A_left =  $(this).offset().left;
								$("select[id!=contacttype][id!=sex][id!=positionId]").hide();
								$("#orgTreeDiv").css({"top":A_top+"px" ,"left":A_left+"px","display":"block"});
							});
							$("#addContactForm").validate({
								rules: {
									"contact.email" : {
										email : true
									},
									"contact.officeCode" : {
										contactCode : true
									},
									"contact.homeCode" : {
										contactCode : true	
									},
									"contact.otherCode" : {
										contactCode : true	
									},
									"contactName" : {
										contactName : true	
									},
									"positionId" : {
										required : true
									}
								},
								messages: {
									"contact.email" : {
										email : "请输入正确的电子邮件"
									},
									"positionId" : {
										required : "单位或职位不能为空"
									}
								},
								submitHandler : function() {
									var formData=$("#addContactForm").serialize();
									$.util.Data.request({
										url:"addContact.action",
										data:formData,
										type:'post',
										dataType:'text', 
										success:function(data){
											$("#detailContact").html(data);
											openMsg("success");
											$("#succMsg").html("添加联系人成功");
											initContact();
											getUsers("allContact");
										},
										error:function(){
											openMsg("failure");
											$("#errMsg1").html("添加联系人出错");
											$("#errMsg2").html("");
										}
									});
								}	
							});
						}	
					});
				});
			});
			//初始化组列表兼组列表操作
			function initContact(){
				$(".btn_person_change").hide();
				var groupUrl = null;
				if(groupType == "org"){//是机构的情况下
					$("#copyUser").show();//只显示复制按钮,不显示转移和删除按钮
					//组织树
					$("#groupList").hide().html("");
					$("#treeArea").show();
					//变换宽度
					changeWidth();
					$.util.Data.request({
						url:"findAllContact.action",
						type:'post',
						dataType:'text', 
						success:function(data){
							//人员列表
							$("#contact").html(data);
							//选中人时的操作
							initBetween();
						}
					});
				}else{
					<sec:authorize  ifAllGranted="通讯录操作" >
					$("#modifyGroup").show();
					</sec:authorize>
					var type = null;
					if(groupType == "private"){
						$(".btn_person_change").show();//个人组显示 组间操作全显示
						groupUrl = "findGroupList.action";
						type=1240;
					}else{
						<sec:authorize  ifAllGranted="通讯录操作" >
						$(".btn_person_change").show();//如果是管理员才全显示
						</sec:authorize>
						$("#copyUser").show();
						groupUrl = "findGroupList.action";
						type=1239
					}
					$("#treeArea").hide();$("#groupList").show();
					//变换宽度
					changeWidth();
					//获取组列表
					getGroups(groupUrl,type);
			    }
			}
			//获取组列表
			function getGroups(groupUrl,type){
				var groupId;
				var contactUrl;
				$.util.Data.request({
					url:groupUrl,
					type:'post',
					data:{'groupType':type},
					dataType:'text', 
					success:function(data){
						$("#groupList").html(data);//组列表
						//组列表鼠标经过样式
						$("div.group_outline > div.group_list").hover(
							function(){
							$(this).addClass("group_list_on");
							},function(){
							$(this).removeClass("group_list_on");
						});
						//选中某组操作
						checkedGroup();
					}
				});
			}
			//选中某组时的操作
			function checkedGroup(){
				$("div#groupList").click(function(event){
					var gro = event.target;
					groupId = $(gro).attr("id");
					//列表选中样式
					if($(gro).attr("class")!='line_dotted'&&$(gro).attr("class")!='group_outline'){
						$("div.group_list").removeClass("group_list_sel").attr("checked","");;
						$(gro).addClass("group_list_sel").attr("checked","checked");
					}
					//如果是所有联系人和最近联系人则只显示复制按钮
					if(groupId=='allContact'||groupId=='inContact'){
						$(".btn_person_change").hide();
						$("#copyUser").show();
					}else{
						<sec:authorize  ifAllGranted="通讯录操作" >
						$(".btn_person_change").show();
						</sec:authorize>
						if(groupType == "private"){
							$(".btn_person_change").show();
						}
					}
					//获取人员
					getUsers(groupId);
			  });
			}
			//获取人员
			function getUsers(groupId){
				//获取组人员数据
				var id = "";
				if(groupId == "allContact"){
					contactUrl = "findAllContact.action";
				}else if(groupId == "inContact"){
					contactUrl = "findRecentContact.action";
				}else{
					contactUrl = "findContactByContactGroupId.action";
					id=groupId;			
				}
				$.util.Data.request({
					url:contactUrl,
					data:{'groupId':id},
					type:'post',
					dataType:'text', 
					success:function(data){
						//人员列表
						$("#contact").html(data);
						//选中人时的操作
						initBetween();
					}
				});
			}
			function queryUser(){
				var searchStr = $("#search_text").val();
				if(searchStr=='输入联系人'){
					return;
				}
				var temp = $("div.group_outline > div.group_list[checked=checked]").attr("id");
				var searchType = (temp==null?"allContact":temp);
				$.util.Data.request({
					url:"getContactListByCondition.action",
					data:{'queryType':'01','searchType':searchType,'contactQuery':searchStr},
					type:'post',
					dataType:'text', 
					success:function(data){
						//查询显示列表
						$("#contact").html(data);
						var nothing = $("#nothing").html();
						if(nothing!=null){
							initContact();
							$("#contact").oneTime(2000,'query',function(){
								$("#allContact").addClass("group_list_sel");
								getUsers("allContact");
								$("#moveUser").hide();
								$("#delUser").hide();
							});
						}else{initBetween();}
					}
				});
			}
			//人员列表操作 
			function initBetween(){
				//人员列表鼠标经过样式
				$("div[id=contact] > div.group_list").hover(function(){
					tempClass = $(this).attr("class");
					$(this).removeClass("blue_list");
					$(this).addClass("group_list_on");
				},function(){
					$(this).removeClass("group_list_on");
					if(!contains($(this).attr("class"),"contact_list_sel",true))
						$(this).addClass(tempClass);
				});
				//选中变色
				var tempClass="";
				var checkedDiv="";
				var addSytle=false;
				//选中获得选中组下的人编辑
				$("div[id^=name]").click(function(){
					var parent = $(this).parent();
					var contactId = $(this).attr("id").substring(4);
					if(checkedDiv!=""&&addSytle){
						$(checkedDiv).addClass("blue_list");
						addSytle=false;
					}	
					checkedDiv=$(parent);
					if(contains(tempClass,"blue_list",true)){
						$(parent).removeClass("blue_list");
						addSytle=true;	
					}
					$("div.group_list").removeClass("contact_list_sel");
					$(parent).addClass("contact_list_sel");
					$("input[type=checkbox]").attr("checked",false);
					$(parent).children("div:first").children("input").attr("checked",true);
					//获得人员信息数据
					$.util.Data.request({
						url:"queryContactById.action",
						type:'post',
						data:{'contactId':contactId},
						dataType:'text', 
						success:function(data){
						$.validator.addMethod("contactCode", function (value, element) {
							if(!value||value.length <= 0)
								return true;
							return /^[1-9][0-9]{5}$/.test(value);
						}, '邮政编码应该为6位数字');
						$.validator.addMethod("contactName", function (value, element) {
							if(!value||value.length <= 0)
								return false;
							return value != "姓名";
						}, '请填写联系人姓名！');
							//人员编辑
							$("#detailContact").html(data);
							$('#contactUnitName').focus(function(){
								tree2.openAll();
								var A_top = $(this).offset().top + $(this).outerHeight(true);
								var A_left =  $(this).offset().left;
								$("select[id!=positionId]").hide();
								$("#orgTreeDiv").css({"top":A_top+"px" ,"left":A_left+"px","display":"block"});
							});
							$('#delContact').click(function() {
								$.util.Data.request( {
										url : "qyeryContactStateById.action" ,
										type : 'post',
										data:{'contactId':$('#conId').val()},
										dataType : 'json',
										success : function(data) {
											if (data == 1) {
												alert('联系人处于启用状态，不能删除');
											}else{
												$("#delMsg").oneTime(200,function(){opendialog("delMsg")});
												$("div#dels > button.btn_confirm").attr("id","UserDel");
												$("#delTitle").html("删除联系人");
												$("#delConfirm").html("确定要移除该联系人?");	
											}
										},
										error:function(){
											openMsg("failure");
											$("#errMsg1").html("删除联系人出错");
										}
									});
							});
							//编辑保存联系人
							$("#editContactForm").validate({
								rules: {
									"contact.contactMobile": {
										digits : true
									},
									"contact.email" : {
										email : true
									},
									"contact.officeCode" : {
										contactCode : true
									},
									"contactName" : {
										contactName : true	
									},
									"positionUser.positionId" : {
										required : true
									}
								},
								messages: {
									"contact.contactMobile" : {
										digits : "请输入数字"
									},
									"contact.email" : {
										email : "请输入正确的电子邮件"
									},
									"positionUser.positionId" : {
										required : "单位或职位不能为空"
									}
								},
								submitHandler : function() {
									var formData=$("#editContactForm").serialize();
									var temp = $("div.group_outline > div.group_list[checked=checked]").attr("id");
									$.util.Data.request({
										url:"editContact.action",
										data:formData,
										type:'post',
										dataType:'text', 
										success:function(data){
											$("#detailContact").html(data);
											openMsg("success");
											$("#succMsg").html("修改联系人成功");
											getUsers(temp);
										},
										error:function(){
											openMsg("failure");
											$("#errMsg1").html("修改联系人出错");
											$("#errMsg2").html("");
										}	
									});
								}	
							});
						}
					});
				});
				//启用,禁用
				$(".text_outline").click(function(){
					$(".text_outline").each(function(){
						$(this).removeClass("text_bold").addClass("text_m_left").next().hide();
					});
					$(this).removeClass("text_m_left").addClass("text_bold").next().show();
				});
				$(".edit_outline").click(function(){
					var edit = $(this);
					var temp = $(this).prev();
					if(confirm("确定要更改联系人的状态?")){
						//启用,禁用
						$.util.Data.request({
							url:"openOrCloseFlag.action",
							data:{'contactId':$(temp).attr("id")},
							type:'post',
							dataType:'json', 
							success:function(data){
								//根据返回至修改显示状态
								if(data==2){
									$(edit).hide();
									$(temp).html("已禁用").removeClass("text_green").addClass("text_red");
									$(temp).removeClass("text_bold").addClass("text_m_left");
								}else{
									$(edit).hide();
									$(temp).html("已启用").removeClass("text_red").addClass("text_green");
									$(temp).removeClass("text_bold").addClass("text_m_left");
								}
							}
						});
					}else{
						$(edit).hide();
						$(temp).removeClass("text_bold").addClass("text_m_left");;
					}
				});
			}
			//组列表变换宽度
			function changeWidth(){
				var display = $("#groupList").css("display");
	            $(".edit_area").css("width",display=="none"?$("#treeArea").width():$("#groupList").width());
			}
			//人员组件操作
			function betweenOper(obj){
				$("ul#groupUl > li").click(function(event){
					var li =event.target;
					$(li).addClass("checked_li");
					var operUrl = "";
					if(obj=="moveUser"){
						operUrl = "removeContactToGroup.action";
					}else{
						operUrl = "addContactToGroup.action";
					}
					var sourceGroupId = $("div.group_outline > div.group_list[checked=checked]").attr("id");
					var groupId = sourceGroupId;
					if(sourceGroupId=='allContact'||sourceGroupId=='inContact'||sourceGroupId==null)
						sourceGroupId = "";
					var targetGroupId = $(li).attr("id");
					var ids = "";
					$("input[type=checkbox]:checked").each(function(i){
						ids+=$(this).val()+",";
					});
					ids=ids.substring(0,ids.length-1);
					$.util.Data.request({
						url:operUrl,
						data:{'contactIds':ids,'sourceGroupId':sourceGroupId,'targetGroupId':targetGroupId},
						type:'post',
						dataType:"text",
						success:function(){
							$("#group").hide();
							if(groupType!='org'){
								initContact();
								if(groupId=="allContact"||groupId=="inContact"){
									$("#moveUser").hide();$("#delUser").hide();
								}
								$("#contact").oneTime(200,function(){
									$("#"+groupId).addClass("group_list_sel").attr("checked","checked");
									getUsers(groupId);
								});
							}else{
								$.util.Data.request({
									url: "findContactByOrgId.action",
									data: orgId,
									async: false,
									dataType: 'text',
									type: "post",
									success: function (data) {$("#contact").html(data);},
									error: function () {$("#contact").html("获取详细信息失败!");}
								});
							}
						},
						error:function(){
							$("#group").hide();
							openMsg("failure");
							$("#errMsg1").html("操作出错");
						}
					});
				});
			}
			//包含方法
			function contains(string,substr,isIgnoreCase){
				if(isIgnoreCase){
					string=string.toLowerCase();
					substr=substr.toLowerCase();
				}
				var startChar=substr.substring(0,1);
				var strLen=substr.length;
				for(var j=0;j<string.length-strLen+1;j++){
					if(string.charAt(j)==startChar){//如果匹配起始字符,开始查找
						if(string.substring(j,j+strLen)==substr){//如果从j开始的字符与str匹配，那ok
							return true;
						} 
					}
		       	}
		       return false;
			}
			//打开编辑框
			function opendialog(obj){
				$('#'+obj).dialog('open');
				$(".ui-dialog-titlebar").hide();
				$('.display_Floater').removeClass("ui-dialog-content")
				.removeClass("ui-widget-content")
				.css("height","150px");//firefox和chrome下高度不对
				$("select").hide();
			}
			function closedialog(obj){
				$("#"+obj).dialog('close');
				$("select").show();
			}
			//打开消息提示框
			function openMsg(obj){
				$("#"+obj).dialog('open');
				$("select").hide();
				$(".ui-dialog-titlebar").hide();
				$(".ui-dialog").css("border","0px");
				$(".operation_tip").removeClass()
				.addClass(obj=="success"?"operation_tip success_outline":"operation_tip failure_outline")
				.css("height","58px");;
				$("#"+obj).oneTime(2000,function(){closedialog(obj);});
			}
			//打开组列表
			function operateUser(obj){
				var groups = $("#group");
				$("#groupUI").html("");
				if($(groups).css("display")=='none'){
					var offset = $(obj).offset();
					var height = $(obj).height();
					$(groups).show().css("z-index","1000")
					.css("left",offset.left)
					.css("top",offset.top+height);
				}else{$(groups).hide();}
			}
		</script>
	</head>
	<body>
		<div id="mainPage" class="surround-layout">
			<jsp:include page="../../jsp/frame/top.jsp" flush="true"></jsp:include>
			<div class="middle">
				<jsp:include page="../../jsp/frame/middle_left.jsp" flush="true">
					<jsp:param value="1037-1038" name="view"/>
				</jsp:include>
				<!-- 右侧输出内容 -->
				<div class="right" >
				  <div class="right-all-content">
				      <table width="100%" cellpadding="0" cellspacing="0" class="directories_outline" >
				        <tr valign="top" >
				          <td width="240">
				             <div class="tab_outline">
				               <div id="public" class="tab_general tab_blue">公共组</div>
				               <div id="private" class="tab_general tab_gray">个人组</div>
				               <div id="org" class="tab_general tab_gray">按机构</div>
				             </div>
				             <div class="edit_area">
				               <div id="modifyGroup" style="display: none;">
           								<div class="icon_outline_r" id="delGroup"><img src="<%=path%>/image/contacts/delete_group.gif" width="16" height="16" alt="删除组"/></div>
           								<div class="icon_outline" id="editGroup"><img src="<%=path%>/image/contacts/pencil.gif" width="16" height="16" alt="编辑组"/></div>
           								<div class="icon_outline" id="addGroup"><img src="<%=path%>/image/contacts/add.gif" width="16" height="16" alt="新增组"/></div>
				               </div>
				               <div id="showTree" style="display: none; float:right; margin-right:5px; margin-top:12px;">
				               		<a href="javascript:void(0)" id="openAll">全部展开</a>
				               </div>
				             </div>
				             <div id="groupList" class="group_outline"></div>
				             <div id="treeArea" class="group_outline" style="display: none;"></div>
				          </td>
				          <td width="280">
				            <div class="search_ouline">
				              <input name="search" id="search_text" type="text" class="search_box" value="输入联系人" />
				              <button class="btn_search" id="search_btn" onmouseover="this.className='btn_search_on'" onmouseout="this.className='btn_search'"></button>
				              <button class="letter_search" id="search_img"></button>
				            </div>
				            <div class="person_change_bar">
				              <button id="moveUser" style="display: none;" class="btn_person_change btn_remove" onmouseover="this.className=' btn_person_change btn_remove_on'" onmouseout="this.className='btn_person_change btn_remove'" title="移至">&nbsp;</button>
				              <button id="copyUser" style="display: none;" class="btn_person_change btn_copy" onmouseover="this.className=' btn_person_change btn_copy_on'" onmouseout="this.className='btn_person_change btn_copy'" title="添加至">&nbsp;</button>
				              <button id="delUser" style="display: none;" class="btn_person_change btn_delete" onmouseover="this.className=' btn_person_change btn_delete_on'" onmouseout="this.className='btn_person_change btn_delete'" title="移出">&nbsp;</button>
				            </div>
				            <div class="btn_bar_bg">
				              <button class="btn_gray_outline gray_border" id="checkedAll" onmouseover="this.className='btn_gray_outline gray_border_dark'" onmouseout="this.className='btn_gray_outline gray_border'" >全选</button>
				              <button class="btn_gray_outline gray_border" id="unCheckedAll" onmouseover="this.className='btn_gray_outline gray_border_dark'" onmouseout="this.className='btn_gray_outline gray_border'" >反选</button>
				            </div>
				            <div id="contact">
				            <!-- 联系人 -->
				            </div>
				             </td>
				          <td>
				            <div class="detail_outline">
				              	<div class="detail_top">
				              	<sec:authorize  ifAllGranted="通讯录操作">
				              		<a><img id="addContact" src="<%=path%>/image/contacts/ru2007.gif" alt="新增联系人" width="20" height="20" hspace="7" vspace="4" /></a>
				             	</sec:authorize>
				              	</div>
				              	<div id="detailContact"></div>
				            </div>
				          </td>
			        	</tr>
				    </table>
				  </div>
				</div>
				<!--  -->
			</div>
		</div>
		<form action="" id="groupForm" name="groupForm" method="post">
		<div id="editGroupName" class="display_Floater">
		  <div class="floater_top"><img src="<%=path %>/image/contacts/top_group.gif" class="top_group" /><span id="saveOrUpdate" class="top_text">新增公共组</span></div>
		  <div class="middle_align">组名：<input type="text" maxlength="10" id="groupName"  class="shadow single-cell" name="groupName"  size="28"/>
		  	<span class="note">*</span>
		  </div>
		  <div>
		    <button id="save_group" class="btn_public btn_confirm">保&nbsp;存</button>
		    <button id="edit_group" class="btn_public btn_confirm">保&nbsp;存</button>
		    <button id="close_group" class="btn_public btn_cancel">取&nbsp;消</button>
		  </div>
		</div>
		</form>
		<div id="delMsg" class="display_Floater">
		  <div class="floater_top""><img src="<%=path %>/image/contacts/top_wrong.gif" class="top_wrong"/><span class="top_text" id="delTitle">删除组中联系人</span></div>
		  <div class="middle_align" id="delConfirm">确定要删除联系人吗？</div>
		  <div id="dels">
		    <button class="btn_public btn_confirm" id="delBtn">确&nbsp;定</button>
		    <button class="btn_public btn_cancel" id="cancelBtn">取&nbsp;消</button>
		  </div>
		</div>
		<div id="letter" style="display:none;border:1px solid #7F9DB9;padding:2px;position:absolute; background-color:white; width: 35px;height: 80px; overflow: auto;">
          <ul style="padding: 2px;">
          	<li id="a-z">全部</li>
          	<li id="a-h">A-H</li>
          	<li id="i-p">I-P</li>
          	<li id="q-w">Q-W</li>
          	<li id="x-z">X-Z</li>
          </ul>
	     </div>
	    <div id="group" style="display:none;border:1px solid #7F9DB9;padding:2px;position:absolute; background-color:white; width: 150px;height: auto; overflow: auto;">
          <ul id="groupUl" style="padding: 2px;">
          </ul>
	     </div>
	     <div id="success" class="operation_tip success_outline">
	     	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	        	<tr>
	          	<td ><strong id="succMsg"></strong></td>
	        	</tr>
	     	</table>
	  	</div>
	    <div id="failure" class="operation_tip failure_outline">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
		          <td ><strong id="errMsg1"></strong></td>
		        </tr>
		        <tr>
		          <td id="errMsg2"></td>
		        </tr>
	        </table>
		</div>
		<div id="orgTreeDiv"></div>
	</body>
</html>